사이트 내 전체검색
PHP
[php] [Function] array_slice()
로빈아빠
https://cmd.kr/php/545 URL이 복사되었습니다.

본문

[Function] array_slice()

array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys ]] )
offset 과 length 인수에 따라 array 로부터 일련의 배열 원소를 반환한다.
예를 들어 배열을 뽑아내고 정렬(usort(), sort())을 한후 정렬된 배열을 일부분 반환 할때 쓸 수 있겠네요.

예)
<?php
$input = array ("a", "b", "c", "d", "e");

$output = array_slice ($input, 2);      // returns "c", "d", and "e"
$output = array_slice ($input, -2, 1);  // returns "d"
$output = array_slice ($input, 0, 3);   // returns "a", "b", and "c"

// 배열 키의 차이에 주의
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));
?>


출력 :
Array ( [0] => c [1] => d ) Array ( [2] => c [3] => d )

댓글목록

등록된 댓글이 없습니다.

PHP
871 (9/18P)

Search

Copyright © Cmd 명령어 3.17.187.116